function freshRem() {
        var dw = window.document.documentElement.clientWidth;
        var font = dw / 10 > 54 ? 54 : dw/10; 
        font += 'px';
        // 1rem = 10vw; width*10%
        window.document.documentElement.style.fontSize = font;
    }
freshRem();

(function(window){
    if( window.document.readyState === "complete") {
        freshRem();
    } else {
        window.document.addEventListener( "DOMContentLoaded", function(){
            freshRem();
        },false);
    }

    window.addEventListener('resize' , function(e) {
        freshRem();
    },false);


    // 下拉及上拉后弹回
    var starty=0,endy=0,mov,change,d,mt,dh,vh,nowmt;
    var dh=window.innerHeight;
    // console.log(dh)
    // var dh=document.documentElement.clientHeight;
    var bd=document.getElementsByTagName('body')[0];
    var view=document.getElementsByClassName('wrap')[0];
    // console.log(view);
    var vh=parseInt($('.wrap').css('height'));
    // console.log(vh);
    // console.log($('.wrap').css('height'));
    bd.addEventListener('touchstart',function(e){
        starty=parseInt(e.changedTouches[0].pageY);
        // console.log(e);
        // console.log(window.getComputedStyle(view, null))
    },false)
    bd.addEventListener('touchmove',function(e){
        mov=parseInt(e.changedTouches[0].pageY);
        nowmt=parseInt(view.style.marginTop);
        change=mov-starty;
        chamt=dh-(vh+nowmt);
        // console.log(chamt);
        d=parseInt(view.style.marginTop)+change;
        if(d>=100||chamt>=170){
            return;
        }
        view.style.marginTop=d+"px";
        starty=mov;
    },false)
    bd.addEventListener('touchend',function(e){
        var mt=parseInt(view.style.marginTop);
        // console.log((dh-55)-vh);
        // console.log(mt);
        if(mt<(dh-55)-vh){
            // var step2=2;
            var clock2=setInterval(function(){
                mt=mt+2;
                if(mt>(dh-85)-vh){
                    mt=(dh-85)-vh;
                    view.style.marginTop=(dh-85)-vh+'px';
                    clearInterval(clock2);
                }else {
                    view.style.marginTop=mt+'px';
                }
            },10);
            // view.style.marginTop=(dh-85)-vh+'px';
        }
        if(mt<0){
            return false;//鼠标向上拖动不用管;
        }
        // var step=mt/20;
        var clock=setInterval(function(){
            mt=mt-2;
            if(mt<0){
                mt=0;
                view.style.marginTop='0px';
                clearInterval(clock);
            }else {
                view.style.marginTop=mt+'px';
            }
        },10);
    },false);



})(window)

// 轮播图
var uls=document.getElementsByClassName('banner-wrap')[0];
var lis=uls.children;
var cirs=document.getElementsByClassName('banner-nav')[0];
var ps=cirs.children;
var num=0;
changeImg(lis,num);

// 图片切换函数
function changeImg(obj,num){
    for(var i = 0;i<obj.length;i++){
        obj[i].style.display='none';
    }
        obj[num].style.display='block';
    for(var i=0;i<ps.length;i++){
        ps[i].style.background='white';
    }
        ps[num].style.background="red";
}

    // for(var i=0;i<ps.length;i++){
    //     ps[i].ontouch = function(){
    //         num=parseInt(this.innerHTML)-1;
    //         changeImg(lis,num);
    //     }
    // }

    // 自动轮播
    function autoPlay(){
        num+=1;
        if(num>lis.length-1){
            num=0;
        }
        changeImg(lis,num);
    }
    var clock = setInterval(autoPlay,1000);